<head>
  <style> body { margin: 0; } </style>

  <script type="importmap">{ "imports": {
    "react": "https://esm.sh/react",
    "react-dom": "https://esm.sh/react-dom/client"
  }}</script>

<!--  <script type="module">import * as React from 'react'; window.React = React;</script>-->
<!--  <script src="../../dist/react-globe.gl.js" defer></script>-->
</head>

<body>
<div id="globeViz"></div>

<script src="//unpkg.com/@babel/standalone"></script>
<script type="text/jsx" data-type="module">
  import Globe from 'https://esm.sh/react-globe.gl?external=react';
  import React from 'react';
  import { createRoot } from 'react-dom';
  import { MeshLambertMaterial } from 'https://esm.sh/three';

  const TILE_MARGIN = 0.35; // degrees

  // Gen random data
  const GRID_SIZE = [60, 20];
  const COLORS = ['red', 'green', 'yellow', 'blue', 'orange', 'pink', 'brown', 'purple', 'magenta'];

  const materials = COLORS.map(color => new MeshLambertMaterial({ color, opacity: 0.6, transparent: true }));
  const tileWidth = 360 / GRID_SIZE[0];
  const tileHeight = 180 / GRID_SIZE[1];
  const tilesData = [];
  [...Array(GRID_SIZE[0]).keys()].forEach(lngIdx =>
    [...Array(GRID_SIZE[1]).keys()].forEach(latIdx =>
      tilesData.push({
        lng: -180 + lngIdx * tileWidth,
        lat: -90 + (latIdx + 0.5) * tileHeight,
        material: materials[Math.floor(Math.random() * materials.length)]
      })
    )
  );

  createRoot(document.getElementById('globeViz')).render(
    <Globe
      tilesData={tilesData}
      tileWidth={tileWidth - TILE_MARGIN}
      tileHeight={tileHeight - TILE_MARGIN}
      tileMaterial="material"
    />
  );
</script>
</body>